package com.example.streamdemo.optional;

import lombok.Data;

import java.io.FileInputStream;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class OptionalTest {
    public static void main(String[] args) {
        Person person=new Person();
        person.setCar(Optional.of(new Car()));
        Car car =  person.getCar().get();
        System.out.println(car.toString());

        ExecutorService executorService = Executors.newFixedThreadPool(12);
        for (;;){
            executorService.submit(OptionalTest::test);
        }
    }

    private static void test()  {
        try {
            FileInputStream fileInputStream = new FileInputStream("D:\\1.txt");
            int available = fileInputStream.available();
            System.out.println(Thread.currentThread().getName()+" "+available);
        }catch (Exception e){
            e.printStackTrace();
        }

//        fileInputStream.close();
    }
}

@Data
class Person{
    private String name;
    @SuppressWarnings("OptionalUsedAsFieldOrParameterType")
    private Optional<Car> car;

}

@Data
class Car{
    private String name;
    @SuppressWarnings("OptionalUsedAsFieldOrParameterType")
    private Optional<Insurance> insurance;
}

@Data
class Insurance{
    private String name;
}
